<template>
  <div>
    <div class="details_header">
      <p>
        <span class="iconfont icon-fanhui" @click="back"></span>
        <span>商品详情</span>
        <span></span>
      </p>
      <img :src="details.shopInfo.shopPic" style="float: left" />
      {{details.shopInfo.shopName}}
    </div>

    <!-- 点菜 -->
    <div class="details_order">
      <div>点菜</div>
      <div>评价</div>
      <div>商家</div>
    </div>
    <!-- 商品详情 -->
    <div class="details_item">
      <div class="details_item_left">
        <!-- 左侧导航 -->
        <div v-for="(item,index) in pageCategoryList" :key="index" @click="onClick(item)">
          <span>{{item.categoryName}}</span>
        </div>
        <div v-for="(item,index) in categoryList" :key="index" @click="onClick(item)">
          <span>{{item.categoryName}}</span>
        </div>
      </div>
      <div class="details_item_right">
        <!-- 右侧内容 -->
        <div v-for="(item,index) in rightList" :key="index" class="details_item_right_style">
          <div class="details_item_right_style_left">
            <img :src="item.bigImageUrl" alt width="100px" />
          </div>
          <div class="details_item_right_style_right">
            <!-- 商品标题 -->
            <p>{{item.spuName}}</p>
            <!-- 商品价格 -->
            <p>￥{{item.currentPrice}}</p>
            <!-- 商品规格 -->
            <p>{{item.unit}}</p>
            <!-- 加购物车 -->
            <span class="cart_span" @click="addCart(item)">+</span>
          </div>
        </div>
      </div>
    </div>

    <!-- 底部 -->
    <div class="details_footer">
      <div class="details_footer_one" @click="onclickShow">
        <van-icon name="shopping-cart-o" :badge="cart.length" size="30" />
      </div>
      <div class="details_price">总价:{{this.$store.state.total}}</div>
    </div>

    <!-- 购物车详情--遮罩层 -->
    <van-overlay style="width:100%;height:676px;" :show="show" @click="show = false">
      <div class="wrapper" @click.stop>
        <div class="block">
          <div class="overlay_xuanz">
            <div class="overlay_xuanz_one">
              <input type="checkbox" :checked="this.$store.state.allChecked" @change="checkedAll" />全选
            </div>
            <div class="overlay_xuanz_two" @click="back2">
              <van-icon name="cross" size="20" />
            </div>
          </div>
          <div class="overlay_list" v-for="(item,index) in cart" :key="index">
            <div class="overlay_check">
              <input type="checkbox" :checked="item.checked" @change="changeChecked(item)" />
            </div>
            <div class="overlay_left">
              <img :src="item.item.littleImageUrl" alt />
            </div>
            <div class="overlay_center">
              <div class="name">{{item.item.spuName}}</div>
              <div class="price">￥{{item.item.currentPrice}}</div>
              <div class="jiajian">
                <button @click="sub(item)">-</button>
                {{item.count}}
                <button @click="add(item)">+</button>
              </div>
            </div>
            <div class="overlay_right">
              <button @click="del(index)">删除</button>
            </div>
          </div>
          <div v-show="this.$store.state.isShow">
            <h4>购物车现在为空哦~</h4>
            <h4>请尽情选购呢！</h4>
          </div>
        </div>
      </div>
    </van-overlay>
  </div>
</template>

<script>
export default {
  data() {
    return {
      rightList: [], //右边内容
      show: false,
    };
  },
  mounted() {
    let id = this.$route.query.id;
    console.log(id);
    this.$store.dispatch("getDetails", id);
  },
  computed: {
    details: function () {
      return this.$store.state.details;
    },
    pageCategoryList: function () {
      return this.$store.state.pageCategoryList;
    },
    categoryList: function () {
      return this.$store.state.categoryList;
    },
    cart: function () {
      return this.$store.state.cart;
    },
  },
  methods: {
    back() {
      //返回事件
      window.history.back();
    },
    onClick(item) {
      //切换右侧内容
      console.log(item);
      this.rightList = item.spuList;
    },
    // 将item添加至购物车
    addCart(item) {
      this.$store.dispatch("add_cart", item);
    },
    onclickShow() {
      this.show = !this.show;
    }, // 点击上面的复选框
    changeChecked(item) {
      this.$store.dispatch("CHANGECHECKED", item);
    },
    checkedAll() {
      this.$store.dispatch("ChECKALL");
    },
    // 隐藏购物车详情--遮罩层
    back2() {
      this.show = false;
    },
    // 删除数据
    del(index) {
      this.$store.dispatch("DELETE_DATA", index);
    },
    // 加数据
    add(item) {
      this.$store.dispatch("ADD_DATA", item);
    },
    // 减
    sub(item) {
      this.$store.dispatch("SUB_DATA", item);
    },
  },
};
</script>

<style scoped>
h4{
  text-align: center;
}
.details_header {
  width: 100%;
  height: 130px;
  background-color: #333;
  color: white;
  padding: 10px 20px;
  box-sizing: border-box;
}
.details_header p {
  height: 30px;
  line-height: 30px;
  display: flex;
  color: wheat;
  justify-content: space-between;
}

.details_header img {
  width: 100px;
  border-radius: 10px;
  margin-right: 15px;
}
.details_order {
  width: 100%;
  height: 50px;
  display: flex;
  justify-content: space-around;
  align-items: center;
  font-size: 16px;
  border-bottom: 1px solid #eeeeee;
}

/* 商品详情样式 */
.details_item {
  width: 100%;
  height: 100%;
  display: flex;
}
.details_item_left {
  width: 30%;
  height: 500px;
  overflow: scroll;
}
.details_item_left div {
  margin: 20px 0px;
  text-align: center;
  font-size: 13px;
}
.details_item_right {
  width: 70%;
  height: 500px;
  overflow: scroll;
}

.details_item_right_style {
  width: 100%;
  display: flex;
  margin: 10px 0px;
  border-bottom: 1px solid #eeeeee;
}
.details_item_right_style img {
  width: 80%;
  height: 70px;
  margin-left: 10%;
}
.details_item_right_style_left {
  flex: 2;
}
.details_item_right_style_right {
  flex: 3;
}
.details_item_right_style_right p {
  font-size: 13px;
}
/* 加购物车 */
.cart_span {
  display: inline-block;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background-color: yellow;
  line-height: 20px;
  text-align: center;
  float: right;
}

/* 底部 */
.details_footer {
  width: 100%;
  height: 50px;
  background-color: white;
  border-top: 1px solid #eeeeee;
  position: fixed;
  bottom: 0;
  left: 0;
  z-index: 10000;
}
.details_price {
  margin-left: 90px;
  margin-top: -15px;
}
.details_footer_one {
  width: 60px;
  height: 60px;
  background-color: #eeeeee;
  border-radius: 50%;
  margin-top: -30px;
  margin-left: 10px;
  text-align: center;
}
.details_footer_one i {
  margin-top: 15px;
}

/* 购物车样式 */
.wrapper {
  height: 100%;
}

.block {
  width: 100%;
  height: 50%;
  position: absolute;
  bottom: 60px;
  background-color: #f6f6f6f6;
  overflow: scroll;
}
.overlay_xuanz {
  width: 100%;
  height: 30px;
  display: flex;
  justify-content: space-between;
  line-height: 30px;
  background-color: white;
}
.overlay_xuanz_one {
  height: 30px;
}
.overlay_xuanz_one input {
  width: 20px;
  height: 20px;
  border: 1px solid #eeeeee;
  background-color: #eeeeee !important;
  margin-left: 10px;
  margin-top: 5px;
}
.overlay_xuanz_two i {
  margin-top: 5px;
  margin-right: 10px;
}
.overlay_list {
  width: 100%;
  height: 100px;
  display: flex;
  margin-top: 10px;
  background-color: white;
}
.overlay_check {
  flex: 0.1;
}
.overlay_check input {
  width: 20px;
  height: 20px;
  border: 1px solid #eeeeee;
  background-color: #eeeeee !important;
  margin-left: 10px;
  margin-top: 40px;
}
.overlay_left {
  flex: 1;
}
.overlay_left img {
  width: 80%;
  height: 90px;
  margin-left: 5%;
  margin-top: 5px;
}
.overlay_center {
  flex: 1.5;
    overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 1;
  -webkit-box-orient: vertical;
}
.overlay_center .name {
  width: 100%;
  height: 40px;
  line-height: 40px;
  text-indent: 20px;
  margin-top: 10px;
}
.overlay_center .price {
  text-indent: 20px;
  font-size: 20px;
  color: red;
}
.overlay_center .jiajian {
  width: 100%;
  height: 50px;
  text-indent: 80px;
  margin-top: -25px;
}
.overlay_center .jiajian button {
  width: 15%;
  height: 30px;
  background-color: white;
  border: 1px solid #eeeeee;
}
.overlay_right {
  flex: 1;
}
.overlay_right button {
  width: 90px;
  height: 40px;
  background-color: brown;
  color: white;
  border: 1px solid gray;
  margin-top: 25px;
  margin-left: 15px;
}
</style>